#ifndef SIGNUPLOGINWIDGET_H
#define SIGNUPLOGINWIDGET_H

#include "TLV.h"
#include <QWidget>
#include <QTcpSocket>

QT_BEGIN_NAMESPACE
namespace Ui { class SignupLoginWidget; }
QT_END_NAMESPACE

class SignupLoginWidget : public QWidget
{
    Q_OBJECT

public:
    SignupLoginWidget(QWidget *parent = nullptr);
    ~SignupLoginWidget();

private slots:
    void on_signupPushButton_clicked();

    void on_loginPushButton_clicked();

private:
    // 发送tlv包，若Tcp未连接或不可写或msg为空，弹窗警告
    void sendTLV(TaskType type, int len, QByteArray msg);
    // 当Tcp连接有新消息到来时，解析出Packet存储在m_packet中，若消息未读完整，m_packet为空
    void readPacket();
    // 清空m_packet
    void clearPacket();

    // 确保发送len字节
    int sendn(QByteArray buf, int len);
    // 从密码行编辑文本框中获取密码，从服务器响应报文中获取setting，生成最终的加密密文
    QString genEncryptedPassword();
    // 拼接QString1长度+QString1+QString2长度+QString2
    QByteArray concatLenValueLenVal(QString str1, QString str2);

private:
    Ui::SignupLoginWidget *ui;
    QTcpSocket *m_pTcpSocket;
    QByteArray m_buffer; // 用于存储未处理完的数据
    Packet m_packet; // 用于解析收到的响应报文，每次readPacket前先clearPacket
};
#endif // SIGNUPLOGINWIDGET_H
